<?php

class UsersController extends AppController {

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('add');
    }

    public function add() {
        if (!empty($this->data)) {
            $this->User->create(); //create data USER
            if ($this->User->save($this->data)) {
                $this->Session->setFlash('User created!');
                $this->redirect(array('action' => 'login'));
            } else {
                $this->Session->setFlash('Please correct the errors');
            }
        }
    }

    public function login() {
        
    }

    public function logout() {
        $this->redirect($this->Auth->logout());
    }

    public function dashboard() {
        
    }

    function _sendNewUserMail($id) {
        $User = $this->User->read(null, $id);
        $this->Email->to = $User['User']['email'];
        $this->Email->bcc = array('thuyet2d@gmail.com');
        $this->Email->subject = 'Welcome to our really cool thing';
        $this->Email->replyTo = 'thuyet2d@gmail.com';
        $this->Email->from = 'Cool Web App <app@example.com>';
        $this->Email->template = 'simple_message'; // note no '.ctp'
        //Send as 'html', 'text' or 'both' (default is 'text')
        $this->Email->sendAs = 'both'; // because we like to send pretty mail
        //Set view variables as normal
        $this->set('User', $User);
        //Do not pass any args to send()
        $this->Email->send();
    }

}

?>
